#include <stdio.h>
#include <stdlib.h>

struct ac{
    int data;
    struct ac *next;
};

void address(struct ac *p)
{
    struct ac *next, **scan;
    struct ac pa;

    pa.data = 10;
    pa.next = &pa;

    next = p->next;
    scan = &p->next;

    printf("pa = %p\n", &pa);
    printf("pa.a = %p\n", &pa.data);
    printf("pa.next = %p\n\n", &pa.next);

    printf("next = %p\n", next);        // 一级指针指向地址 p->next
    printf("scan = %p\n", scan);        // 一级指针地址     &p->next
    printf("*scan = %p\n\n", *scan);    // 一级指针指向地址 p->next

    printf("p->next = %p\n", p->next);                  // 一级指针指向地址 p->next
    printf("p->next->next = %p\n", p->next->next);      // 一级指针指向地址 p->next->next
    printf("p->next->next->next = %p\n\n", p->next->next->next);      // 一级指针指向地址 p->next->next->next

    printf("&p->next->next = %p\n", &p->next->next);        // 一级指针地址
    printf("&(p->next)->next = %p\n", &(p->next)->next);    // 一级指针地址
    printf("&(p->next->next) = %p\n\n", &(p->next->next));  // 一级指针地址

    printf("(*scan)->next = %p\n\n", (*scan)->next);    // 一级指针指向地址 p->next->next
    //printf("*scan->next = %p\n", *scan->next);        // error: ‘*scan’ is a pointer; did you mean to use ‘->’?
    //printf("scan->next = %p\n", scan->next);          // error: ‘*scan’ is a pointer; did you mean to use ‘->’?

    if ((*scan)->next == next) {
        printf("ditto\n\n");
    }

    p->next->next = &pa;
    printf("next = %p\n", next);        // 一级指针指向地址 p->next 
    printf("scan = %p\n", scan);        // 一级指针地址     &p->next
    printf("*scan = %p\n", *scan);      // 一级指针指向地址 p->next
    printf("(*scan)->next = %p\n", (*scan)->next);      // 一级指针指向地址 p->next->next
    //printf("*scan->next = %p\n", *scan->next);        // error: ‘*scan’ is a pointer; did you mean to use ‘->’?
    printf("p->next->next = %p\n", p->next->next);      // 一级指针指向地址 p->next->next
}

int main()
{
    struct ac p;

    p.data = 10;
    p.next = &p;

    printf("p = %p\n", &p);
    printf("p.a = %p\n", &p.data);
    printf("p.next = %p\n\n", &p.next);
    address(&p);

    return 0;
}

#if 0
p = 0x7ffef0ac54b0
p.a = 0x7ffef0ac54b0
p.next = 0x7ffef0ac54b8

pa = 0x7ffef0ac5480
pa.a = 0x7ffef0ac5480
pa.next = 0x7ffef0ac5488

next = 0x7ffef0ac54b0
scan = 0x7ffef0ac54b8
*scan = 0x7ffef0ac54b0

p->next = 0x7ffef0ac54b0
(*scan)->next = 0x7ffef0ac54b0

ditto

next = 0x7ffef0ac54b0
scan = 0x7ffef0ac54b8
*scan = 0x7ffef0ac5480
(*scan)->next = 0x7ffef0ac5480
p->next->next = 0x7ffef0ac5480
#endif
